<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>rendererharness.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_testing_ui_rendererharness.js.html">rendererharness.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>// All Rights Reserved
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview A driver for testing renderers.
<a name="line18"></a> *
<a name="line19"></a> * @author nicksantos@google.com (Nick Santos)
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.testing.ui.RendererHarness&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.Disposable&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.NodeType&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.asserts&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.dom&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>/**
<a name="line32"></a> * A driver for testing renderers.
<a name="line33"></a> *
<a name="line34"></a> * @param {goog.ui.ControlRenderer} renderer A renderer to test.
<a name="line35"></a> * @param {Element} renderParent The parent of the element where controls will
<a name="line36"></a> *     be rendered.
<a name="line37"></a> * @param {Element} decorateParent The parent of the element where controls will
<a name="line38"></a> *     be decorated.
<a name="line39"></a> * @constructor
<a name="line40"></a> * @extends {goog.Disposable}
<a name="line41"></a> */
<a name="line42"></a>goog.testing.ui.RendererHarness = function(renderer, renderParent,
<a name="line43"></a>    decorateParent) {
<a name="line44"></a>  goog.Disposable.call(this);
<a name="line45"></a>
<a name="line46"></a>  /**
<a name="line47"></a>   * The renderer under test.
<a name="line48"></a>   * @type {goog.ui.ControlRenderer}
<a name="line49"></a>   * @private
<a name="line50"></a>   */
<a name="line51"></a>  this.renderer_ = renderer;
<a name="line52"></a>
<a name="line53"></a>  /**
<a name="line54"></a>   * The parent of the element where controls will be rendered.
<a name="line55"></a>   * @type {Element}
<a name="line56"></a>   * @private
<a name="line57"></a>   */
<a name="line58"></a>  this.renderParent_ = renderParent;
<a name="line59"></a>
<a name="line60"></a>  /**
<a name="line61"></a>   * The original HTML of the render element.
<a name="line62"></a>   * @type {string}
<a name="line63"></a>   * @private
<a name="line64"></a>   */
<a name="line65"></a>  this.renderHtml_ = renderParent.innerHTML;
<a name="line66"></a>
<a name="line67"></a>  /**
<a name="line68"></a>   * Teh parent of the element where controls will be decorated.
<a name="line69"></a>   * @type {Element}
<a name="line70"></a>   * @private
<a name="line71"></a>   */
<a name="line72"></a>  this.decorateParent_ = decorateParent;
<a name="line73"></a>
<a name="line74"></a>  /**
<a name="line75"></a>   * The original HTML of the decorated element.
<a name="line76"></a>   * @type {string}
<a name="line77"></a>   * @private
<a name="line78"></a>   */
<a name="line79"></a>  this.decorateHtml_ = decorateParent.innerHTML;
<a name="line80"></a>};
<a name="line81"></a>goog.inherits(goog.testing.ui.RendererHarness, goog.Disposable);
<a name="line82"></a>
<a name="line83"></a>
<a name="line84"></a>/**
<a name="line85"></a> * A control to create by decoration.
<a name="line86"></a> * @type {goog.ui.Control}
<a name="line87"></a> * @private
<a name="line88"></a> */
<a name="line89"></a>goog.testing.ui.RendererHarness.prototype.decorateControl_;
<a name="line90"></a>
<a name="line91"></a>
<a name="line92"></a>/**
<a name="line93"></a> * A control to create by rendering.
<a name="line94"></a> * @type {goog.ui.Control}
<a name="line95"></a> * @private
<a name="line96"></a> */
<a name="line97"></a>goog.testing.ui.RendererHarness.prototype.renderControl_;
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>/**
<a name="line101"></a> * Whether all the necessary assert methods have been called.
<a name="line102"></a> * @type {boolean}
<a name="line103"></a> * @private
<a name="line104"></a> */
<a name="line105"></a>goog.testing.ui.RendererHarness.prototype.verified_ = false;
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * Attach a control and render its DOM.
<a name="line110"></a> * @param {goog.ui.Control} control A control.
<a name="line111"></a> * @return {Element} The element created.
<a name="line112"></a> */
<a name="line113"></a>goog.testing.ui.RendererHarness.prototype.attachControlAndRender =
<a name="line114"></a>    function(control) {
<a name="line115"></a>  this.renderControl_ = control;
<a name="line116"></a>
<a name="line117"></a>  control.setRenderer(this.renderer_);
<a name="line118"></a>  control.render(this.renderParent_);
<a name="line119"></a>  return control.getElement();
<a name="line120"></a>};
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * Attach a control and decorate the element given in the constructor.
<a name="line125"></a> * @param {goog.ui.Control} control A control.
<a name="line126"></a> * @return {Element} The element created.
<a name="line127"></a> */
<a name="line128"></a>goog.testing.ui.RendererHarness.prototype.attachControlAndDecorate =
<a name="line129"></a>    function(control) {
<a name="line130"></a>  this.decorateControl_ = control;
<a name="line131"></a>
<a name="line132"></a>  control.setRenderer(this.renderer_);
<a name="line133"></a>
<a name="line134"></a>  var child = this.decorateParent_.firstChild;
<a name="line135"></a>  assertEquals(&#39;The decorated node must be an element&#39;,
<a name="line136"></a>               goog.dom.NodeType.ELEMENT, child.nodeType);
<a name="line137"></a>  control.decorate(/** @type {Element} */ (child));
<a name="line138"></a>  return control.getElement();
<a name="line139"></a>};
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Assert that the rendered element and the decorated element match.
<a name="line144"></a> */
<a name="line145"></a>goog.testing.ui.RendererHarness.prototype.assertDomMatches = function() {
<a name="line146"></a>  assert(&#39;Both elements were not generated&#39;,
<a name="line147"></a>         !!(this.renderControl_ &amp;&amp; this.decorateControl_));
<a name="line148"></a>  goog.testing.dom.assertHtmlMatches(
<a name="line149"></a>      this.renderControl_.getElement().innerHTML,
<a name="line150"></a>      this.decorateControl_.getElement().innerHTML);
<a name="line151"></a>  this.verified_ = true;
<a name="line152"></a>};
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Destroy the harness, verifying that all assertions had been checked.
<a name="line157"></a> * @override
<a name="line158"></a> * @protected
<a name="line159"></a> */
<a name="line160"></a>goog.testing.ui.RendererHarness.prototype.disposeInternal = function() {
<a name="line161"></a>  // If the harness was not verified appropriately, throw an exception.
<a name="line162"></a>  assert(&#39;Expected assertDomMatches to be called&#39;,
<a name="line163"></a>         this.verified_ || !this.renderControl_ || !this.decorateControl_);
<a name="line164"></a>
<a name="line165"></a>  if (this.decorateControl_) {
<a name="line166"></a>    this.decorateControl_.dispose();
<a name="line167"></a>  }
<a name="line168"></a>  if (this.renderControl_) {
<a name="line169"></a>    this.renderControl_.dispose();
<a name="line170"></a>  }
<a name="line171"></a>
<a name="line172"></a>  this.renderParent_.innerHTML = this.renderHtml_;
<a name="line173"></a>  this.decorateParent_.innerHTML = this.decorateHtml_;
<a name="line174"></a>
<a name="line175"></a>  goog.testing.ui.RendererHarness.superClass_.disposeInternal.call(this);
<a name="line176"></a>};
</pre>


</body>
</html>
